<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>白嫖电影</title>

    <!-- === CSS === -->
    <link rel="stylesheet" href="bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/materialize.min.css">
    <link rel="stylesheet" href="css/owl.carousel.min.css">
    <link rel="stylesheet" href="css/ionicons.css">
    <link rel="stylesheet" href="css/app.css">

    <style>
        .movie-catalog {
            width: 80%;
            height: 30px;
            margin: 80px auto;
            display: flex;
            outline: 5px solid #ffffff;
        }

        .movie-catalog li {
            color: #fefefe;
            width: 80px;
            height: 30px;
        }

        .movie-list {
            display: flex;
            /*justify-content: space-around;*/
            justify-content:flex-start;
            flex-flow: row wrap;
        }

        .movie-list .item {
            padding: 6px 12px;
            /*padding-bottom: 12px;*/
        }

        .movie-catalog li {
            cursor: pointer;
        }

        .movie-catalog li.active {
            color: #E82027;
        }
    </style>
</head>
<body>

<!--=== 电影网站的导航栏开始 ===-->
<header class="header" style="background: #17181A;width: 100%; height: 62px;">
    <iframe id="movie-nav-bar" src="movie-header-nologin.html" style="width:100%; height: 62px;" wmode="transparent"
            frameborder="0" allowfullscreen></iframe>
</header>
<!--=== 电影网站的导航栏结束===-->


<!--=== movies 7 ===-->
<section class="movies movie-7 movie-box movie-modify-7-2" style="height: 160px">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <ul class="movie-catalog" id="movie-catalog-list">
                    <li class="active">全部</li>
                    <li>爱情</li>
                    <li>喜剧</li>
                    <li>动作</li>
                    <li>犯罪</li>
                    <li>惊悚</li>
                    <li>动画</li>
                    <li>纪录</li>
                </ul>
            </div>
        </div>
    </div>
</section>

<!--=== movies 1 ===-->
<section class="movies movie-1">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="wrap-movie">
                    <div class="section-title-wrap">
                        <div class="section-title">电影列表</div>
                    </div>
                    <div class="movie-list" id="movie-list-container">
                        <!--第一行电影
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/The-Witcher-3-Wild-Hunt.jpg"
                                     alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">The Witcher 3</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>9/10</div>
                                    <div class="movie-item-genre">Action, Crime, Drama</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/uncharted-4.jpg" alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Uncharted 4</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>8/10</div>
                                    <div class="movie-item-genre">Action, Crime</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/batman-arkham-knight.jpg"
                                     alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Batman arkham knight</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>7/10</div>
                                    <div class="movie-item-genre">Action, Drama</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/tomb-rider.jpg" alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Tomb-rider</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>6/10</div>
                                    <div class="movie-item-genre">Crime, Drama</div>
                                </div>
                            </div>
                        </div>
                        -->
                        <!--第二行电影
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/The-Witcher-3-Wild-Hunt.jpg"
                                     alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">The Witcher 3</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>9/10</div>
                                    <div class="movie-item-genre">Action, Crime, Drama</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/uncharted-4.jpg" alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Uncharted 4</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>8/10</div>
                                    <div class="movie-item-genre">Action, Crime</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/batman-arkham-knight.jpg"
                                     alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Batman arkham knight</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>7/10</div>
                                    <div class="movie-item-genre">Action, Drama</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/tomb-rider.jpg" alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Tomb-rider</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>6/10</div>
                                    <div class="movie-item-genre">Crime, Drama</div>
                                </div>
                            </div>
                        </div>
                        -->
                        <!--第三行电影
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/The-Witcher-3-Wild-Hunt.jpg"
                                     alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">The Witcher 3</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>9/10</div>
                                    <div class="movie-item-genre">Action, Crime, Drama</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/uncharted-4.jpg" alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Uncharted 4</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>8/10</div>
                                    <div class="movie-item-genre">Action, Crime</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/batman-arkham-knight.jpg"
                                     alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Batman arkham knight</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>7/10</div>
                                    <div class="movie-item-genre">Action, Drama</div>
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="images/poster/tomb-rider.jpg" alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">Tomb-rider</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>6/10</div>
                                    <div class="movie-item-genre">Crime, Drama</div>
                                </div>
                            </div>
                        </div>
                        -->
                    </div>
                </div>
            </div>

            <div style="margin: 0px auto">
                <ul class="pagination" id="movie-pagination">
                    <!--
                    <li class="page-item"><a class="page-link" href="#">上一页</a></li>
                    <li class="page-item"><a class="page-link" href="#">1</a></li>
                    <li class="page-item"><a class="page-link" href="#">2</a></li>
                    <li class="page-item"><a class="page-link" href="#">3</a></li>
                    <li class="page-item"><a class="page-link" href="#">下一页</a></li>
                    -->
                </ul>
            </div>
        </div>
    </div>
</section>


<!--=== Modal For All Videos ===-->
<div class="modal popup-video fade" id="call-video" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="close" data-dismiss="modal" aria-label="Close"><i class="ion ion-ios-close-outline"></i>
                </div>
                <!-- 16:9 aspect ratio -->
                <div class="embed-responsive embed-responsive-16by9">
                    <iframe class="embed-responsive-item" src="" id="video" allowscriptaccess="always"
                            allowfullscreen></iframe>
                </div>
            </div>
        </div>
    </div>
</div>

<!--=== footer area ===-->
<section class="footer-area">
    <div class="container">
        <div class="row">
            <div class="col-lg-3 col-md-4 col-sm-6">
                <div class="footer-logo"><img src="images/small-image/moviez-logo.png" alt="footer logo"></div>
                <div class="subscribe">
                    <p>做中国影迷最喜欢的免费电影资源库！<br>我们的口号是：永远白嫖，永不收费！</p>
                </div>

            </div>
            <div class="col-lg-3 col-md-4 col-sm-6">
                <div class="footer-item-title"><h4>商务合作</h4></div>
                <div class="just-links">
                    <ul class="list-unstyled">
                        <li class=""><a href="#">招商引资</a></li>
                        <li class=""><a href="#">意见投诉</a></li>
                        <li class=""><a href="#">我要求片</a></li>
                        <li class=""><a href="#">版权声明</a></li>
                    </ul>
                </div>
            </div>
            <div class="col-lg-3 col-md-4 col-sm-6">
                <div class="footer-item-title"><h4>友情链接</h4></div>
                <div class="just-links">
                    <ul class="list-unstyled">
                        <li class=""><a href="#">豆瓣网</a></li>
                        <li class=""><a href="#">中国电影网</a></li>
                        <li class=""><a href="#">1080影视大全</a></li>
                        <li class=""><a href="#">爱奇艺</a></li>
                        <li class=""><a href="#">牛牛编程</a></li>
                    </ul>
                </div>
            </div>
            <div class="col-lg-3 col-md-4 col-sm-6">
                <div class="footer-item-title"><h4>投资者关系</h4></div>
                <div class="just-links">
                    <ul class="list-unstyled">
                        <li class=""><a href="#">关于我们</a></li>
                        <li class=""><a href="#">公司简介</a></li>
                        <li class=""><a href="#">发展历程</a></li>
                        <li class=""><a href="#">加入我们</a></li>
                        <li class=""><a href="#">联系我们</a></li>
                    </ul>
                </div>
            </div>
            <hr class="d-md-none d-lg-block">
        </div>


        <hr>
        <div class="row">
            <div class="col-12">
                <div class="footer-wrap text-center">
                    <!--ul class="list-inline social-icon">
                        <li class="list-inline-item"><i class="ion ion-social-twitter"></i></li>
                        <li class="list-inline-item"><i class="ion ion-social-linkedin"></i></li>
                        <li class="list-inline-item"><i class="ion ion-social-dribbble-outline"></i></li>
                    </ul-->
                    <div class="footer-tag">2018-2023 &copy; 华清远见 | 作者：西蒙牛</div>
                </div>
                <div style="text-align: center;color: #ccc">
                    [<a href="admin/login.html">后台管理</a>]
                </div>
            </div>
        </div>
    </div>
</section>


<!-- ==== js ==== -->
<script src="js/jquery-2.2.3.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/materialize.min.js"></script>
<script src="js/app.js"></script>
<script src="js/util/outils.min.js"></script>
<script src="js/api/baseUrl.js"></script>

<script src="js/auth.js"></script>
<script src="js/api/movie_type.js"></script>
<script src="js/api/movie.js"></script>

<script type="module">

    let isLogin = await authLoginStatus().then(resp => {
        console.log("-------在login.html页面中判断的登录状态-------")
        console.log(resp);
        return resp;
    });

    if (isLogin) {
        $("#movie-nav-bar").prop("src", 'movie-header-islogin.html')
    } else {
        $("#movie-nav-bar").prop("src", 'movie-header-nologin.html')
    }
</script>

<script>

    let movieTypesList = [
        {
            "id": 0,
            "type": "全部"
        }
    ];
    let currentActiveMovieType = 0; //默认第一项被激活。
    let movieList = []; //当前板块下的电影列表；

    let pager = {}; //当前分页对象。

    queryAllMovieType().then(resp => {
        if (resp.code === 200) {
            movieTypesList = [movieTypesList[0], ...resp.data]; //展开语法追加....
            console.log("---------电影分类列表--------");
            console.log(movieTypesList);
            refreshMovieTypesList(currentActiveMovieType);

        }
    })

    function refreshMovieTypesList(currentActiveIndex) {
        console.log('重新绘制电影分类列表....')
        $("#movie-catalog-list").empty();
        html = '';
        for (let i = 0; i < movieTypesList.length; i++) {
            let t = movieTypesList[i];
            if (i === currentActiveIndex) {
                html += `<li class="active" onclick="refreshMovieTypesList(${i})">${t.type}</li>`;
            } else {
                html += `<li onclick="refreshMovieTypesList(${i})">${t.type}</li>`;
            }

        }
        $("#movie-catalog-list").append(html);

        //重绘电影列表
        refreshMovieList(movieTypesList[currentActiveIndex].type, 1);
    }

    function refreshMovieList(type, currentPageNumber) {
        queryMoviePagerByType(type, currentPageNumber).then(resp => {
            if (resp.code === 200) {
                pager = resp.data;
                console.log("---------当前的分页对象是----------")
                console.log(pager);
                movieList = resp.data.records;
                console.log("---------当前板块下的电影集合是-------------")
                console.log(movieList);

                console.log('---------开始重绘电影列表界面..-----------')
                $("#movie-list-container").empty();
                let html = '';

                for (let i = 0; i < movieList.length; i++) {
                    let m = movieList[i];
                    html += `<div class="item">
                            <div class="movie-item">
                                <img class="movie-item-img" src="${m.logo}"
                                     alt="Movie Thumb">
                                <div class="movie-item-overlay">
                                    <div class="movie-item-title">${m.name}</div>
                                    <div class="movie-item-rate"><i class="ion ion-android-star"></i>${m.playDate}</div>
                                    <div class="movie-item-genre">${m.director}</div>
                                </div>
                            </div>
                        </div>`;
                }
                $("#movie-list-container").append(html);

                //做完这一步，认为电影列表已经渲染完毕！！！
                //下一步应该渲染分页组件。
                refreshMoviePager(type)
            }
        })
    }

    //重绘分页组件
    function refreshMoviePager(type) {

        $("#movie-pagination").empty();
        let html = '';
        //判断当前page对象里当前页号只要不是1，就可以使用上一页
        if(pager.current ===1){
            html +=`<li class="page-item"><a class="page-link" href="javascript:void(0);">上一页</a></li>`
        }else{
            html +=`<li class="page-item"><a class="page-link" href="javascript:refreshMovieList('${type}',${pager.current-1})">上一页</a></li>`
        }
        for (let i = 0; i< pager.pages; i++) {
            if((i+1)=== pager.current){
                html += `<li class="page-item"><a class="page-link" style="color: #E82027" href="javascript:refreshMovieList('${type}',${i+1})">${i+1}</a></li>`
            }else{
                html += `<li class="page-item"><a class="page-link" href="javascript:refreshMovieList('${type}',${i+1})">${i+1}</a></li>`
            }
        }
        if(pager.current === pager.pages){
            html += `<li class="page-item"><a class="page-link" href="javascript:void(0);">下一页</a></li>`;
        }else{
            html += `<li class="page-item"><a class="page-link" href="javascript:refreshMovieList('${type}',${pager.current+1})">下一页</a></li>`;
        }


        $("#movie-pagination").append(html);
    }
</script>
</body>
</html>
